10 my $adiumUser = undef;
16 my %Protocols = ( #Map gaim protocol IDs to Adium ones
21 "jabber"=> "Jabber", # both jabber and gtalk
22 #Add the rest here, or tell me what they are, someone who uses other protocols
28 print "Error: $msg\n\n" if $msg;
29 print "Usage: gaim2adium.pl [--adiumUser <user> | --outDir <output dir>] [--inDir <input dir>] [--yes]\n";
30 print "Options: (defaults)\n\n";
31 print "\tinDir:\t\t\tDirectory to import logs from (~/.gaim/logs)\n";
32 print "\toutDir:\t\t\tDirectory to import logs to (./Logs)\n";
33 print "\tadiumUser:\t\tAttempt to automatically import logs to the specified Adium user\n";
34 print "\tforce\t\t\tOverwrite existing logs\n";
35 print "\tskip\t\t\tSkip existing logs\n";
36 print "\thelp:\t\t\tDisplay this help.\n";
37 print "\nOnce the logs have been imported, the contents of outDir can be dragged to your Adium log folder\n\n";
44 #gaim logs are LOG_BASE/Protocol/Account/Contact/YYYY-MM-DD-TIME.(html|txt)
45 if($File::Find
::name
=~ m
! ^ $inDir # top level dir
47 ([^/]+)/ # 1 - protocol
48 ([^/]+)/ # 2 - account
49 ([^/]+)/ # 3 - contact
56 (?
:-(\d
{4})\w
{3})?
# 10 - optional timezone
57 \
.(html
|txt
) # 11 - extension
60 my ($proto,$acct,$contact,$year,$month,$day,$hour,$min,$seconds,$tz,$ext) = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);
61 return unless defined ($proto = $Protocols{lc $proto});
62 if ($proto eq 'Jabber' and $acct =~ /gmail\.com/) {
66 $foundLogs = 1; #Set the logs found flag
67 my $outFN = defined($tz) ?
"$contact ($year-$month-${day}T$hour.$min.$seconds-$tz)." : "$contact ($year|$month|$day).";
68 $outFN .= ((lc $ext) eq "html") ?
"html" : "adiumLog";
69 unless (-d
"$outDir/$proto.$acct/$contact") {
70 unless (-d
"$outDir/$proto.$acct") {
71 mkdir("$outDir/$proto.$acct") or die "Can't mkdir $outDir/$proto.$acct: $!";
73 mkdir("$outDir/$proto.$acct/$contact") or die "Can't mkdir $outDir/$proto.$acct/$contact: $!";
75 my $file = "$outDir/$proto.$acct/$contact/$outFN";
76 return if(-e
$file && $skip);
77 if(-e
$file && !$force)
79 #print(($adiumUser?"$adiumUser already has":"There already exists"),
80 #" a log from $proto.$acct to $contact on $day/$month/$year.\n");
81 `cat '$_' >> '$file'`;
83 copy
($_,$file) or die "Failed to copy $_ to $file: $!";
85 `touch -t $year$month$day$hour$min.$seconds '$file'`;
89 #Sort a list of log files by time
93 return sort logcmp
@files;
99 $t1 = $& if $a =~ /\d{6}/;
100 $t2 = $& if $b =~ /\d{6}/;
101 return 0 unless defined($t1) && defined($t2);
106 GetOptions
( "adiumUser=s" => \
$adiumUser,
107 "inDir=s" => \
$inDir,
108 "outDir=s" => \
$outDir,
115 usage
("You must supply at most one of adiumUser and outDir") if defined($outDir) && defined($adiumUser);
117 $outDir ||= "$ENV{HOME}/Library/Application Support/Adium 2.0/Users/$adiumUser/Logs" if defined $adiumUser;
118 $outDir ||= "$ENV{PWD}/Logs";
120 $outDir = "$ENV{PWD}/$outDir" unless $outDir =~ m
!^/!;
123 $inDir ||= "$ENV{HOME}/.gaim/logs";
125 print "NOTE: Output directory exists, existing logs will be appended to.\n" if(-d
$outDir);
127 mkdir($outDir) unless -e
$outDir;
128 usage
("Output dir must be a directory") unless -d
$outDir;
129 usage
("Output dir must be writeable") unless -w
$outDir;
131 usage
("Input directory '$inDir' does not exist") unless -d
$inDir;
132 usage
("Input directory '$inDir' is not readable") unless -r
$inDir;
135 find
({wanted
=> \
&process_log
,
136 preprocess
=> \
&sort_logs
}, $inDir);
138 #Warn if we didn't find any logs
141 print "Warning: No recognized logs found.\n";
142 print "Note:\tThis script only supports logs generated by gaim 0.73 and above.\n";
143 print "\tYou may be able to update older gaim logs to the new format using the script from\n";
144 print "\thttp://sourceforge.net/forum/message.php?msg_id=2392758\n";